﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sort
{
    static class SelectionSort
    {
        static void Main()
        {
            Console.WriteLine("SelectionSort.");
            int[] arr = { 1, 2, 3, 5, 0, 9, 8, 7, 6, 4 };
            Random rd = new Random();

            for (int j = 0; j < 1000; j++)
            {
                for (int i = 0; i < 10; i++)
                {
                    arr[i] = rd.Next(20);
                }

                Sort(arr);

                if (!Utils.CheckOrderArray(arr))
                {
                    Console.WriteLine("SelectionSort error.");
                }
                //Utils.WriteArr(arr);
            }
        }

        public static void Sort(int[] arr)
        {
            int len = arr.Length;
            int sortNum = 0;

            while (sortNum < len)
            {
                int minIdx = sortNum;
                int minValue = arr[sortNum];
                for (int i = sortNum; i < len; i++)
                {
                    if (arr[i] < minValue)
                    {
                        minValue = arr[i];
                        minIdx = i;
                    }
                }
                Utils.Swap(arr, sortNum, minIdx);
                sortNum++;
            }
        }
    }
}
